package com.example.kafka.service;

import com.alibaba.fastjson.JSON;
import com.example.kafka.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ConsumerService {

    @KafkaListener(topics = "user-topic")
    public void message(String message) {
        if (!StringUtils.isEmpty(message)) {
            User user = JSON.parseObject(message, User.class);
            System.out.println(user);
        }
        log.info("收到消息 : {}", message);
    }
}
